Q: Space complexity for an adjacency list of an undirected graph having large values of V (vertices) and E (edges) is ___________
Solution: In an adjacency list for every vertex there is a linked list which have the values of the edges to which it is connected.
Q: For some sparse graph an adjacency list is more space efficient against an adjacency matrix.
Solution: Space complexity for adjacency matrix is always O(V*V) while space complexity for adjacency list in this case would be O(V).
Q: Time complexity to find if there is an edge between 2 particular vertices is _________
Solution: The maximum edges a vertex can have is V-1.
Q: For the given conditions, which of the following is in the correct order of increasing space requirement? i) Undirected, no weight ii) Directed, no weight iii) Directed, weighted iv) Undirected, weighted
Solution: i) takes v+4e, ii) takes v+2e, iii) takes v+3e, iv) takes v +6e space.
Q: Space complexity for an adjacency list of an undirected graph having large values of V (vertices) and E (edges) is __________
Solution: In an adjacency list for every vertex there is a linked list which have the values of the edges to which it is connected.
Q: Complete the given snippet of code for the adjacency list representation of a weighted directed graph. class neighbor { int vertex, weight; ____ next; } class vertex { string name; _____ adjlist; } vertex adjlists[101];
Solution: Vertex would have a name and a linked list attached to it.
Q: In which case adjacency list is preferred in front of an adjacency matrix?
Solution: In case of sparse graph most of the entries in the adjacency matrix would be 0, hence adjacency list would be preferred.
Q: To create an adjacency list C++’s map container can be used.
Solution: We can create a mapping from string to a vector, where string would be the name of the vertex and vector would contains the name of the vertices to which it is connected.
Q: What would be the time complexity of the following function which adds an edge between two vertices i and j, with some weight ‘weigh’ to the graph having V vertices? vectoradjacent[15] ; vector weight[15]; void addEdge(int i,int j,int weigh) { adjacent[a].push_back(i); adjacent[b].push_back(j); weight[a].push_back(weigh); weight[b].push_back(weigh); }
Solution: The function win in the constant time as all the four step takes constant time.
Q: What would be the time complexity of the BFS traversal of a graph with n vertices and n1.25 edges?
Solution: The time complexity for BFS is O(|V| + |E|) = O(n + n1.25) = O(n1.25).
You Have Score    | /10 |